package com.zyf.hos.gw.controller;

import com.alibaba.fastjson.JSONObject;
import com.zyf.hos.gw.util.CountUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Calendar;
import java.util.Date;

@Controller
@RequestMapping("/")
public class BaseController {

    @Autowired
    CountUtil countUtil;

    @RequestMapping("{url}.html")
    public String url(@PathVariable("url") String url){
        return url;
    }

    @RequestMapping("count")
    @ResponseBody
    public String count(){

        if (countUtil!=null){
            //失效
            System.out.println(countUtil.getBeginTime());
            System.out.println(countUtil.isFlag());
            if (countUtil.isFlag(new Date())){
                countUtil.setBeginTime(new Date());
                countUtil.setName("新的");
                System.out.println("失效");
            }
        }
        return JSONObject.toJSONString(countUtil);
    }
}
